package arithmetic;

import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;

import org.junit.jupiter.api.Test;

/**
 * @author jiangfeng
 * Created on 2020-03-12
 */
public class TestURLAndURI {

    String s0="https://www.aaa.com/abc/cd?x=123";
    String s1="https://www.aaa.com#www.bbb.com?x=123";
    String s2="https://www.aaa.com\\www.bbb.com?x=123";

    public static void main(String[] args) throws Exception {
        TestURLAndURI test = new TestURLAndURI();
        test.testURL();
        //test.testURI();
    }

    /**
     * 测试结果:
     * www.aaa.com
     * www.aaa.com
     * 报错
     */
    @Test
    public void testURI() throws URISyntaxException {
        URI uri0 = new URI(s0);
        System.out.println(uri0.getHost());


        URI uri1 = new URI(s1);
        System.out.println(uri1.getHost());


        URI uri2 = new URI(s2);
        System.out.println(uri2.getHost());

    }

    /**
     * 测试结果:
     * www.aaa.com
     * www.aaa.com
     * www.aaa.com\www.bbb.com
     */
    @Test
    public void testURL() throws MalformedURLException {
        URL url0 = new URL(s0);
        URL url1 = new URL(s1);
        URL url2 = new URL(s2);

        System.out.println(url0.getHost());
        System.out.println(url1.getHost());
        System.out.println(url2.getHost());

    }
}
